import { AxiosPromise } from 'axios'
import request from './request'

/**
 * 获取金蝶云星空配置信息
 */
export function getYunxkCfig() {
  return request({
    url: '/kingdee/yunxk/set/getYunxkCfig',
    method: 'get',
  })
}

/**
 * 保存星空对接配置
 *@param {boolean} enabled 是否启用星空接口：false-关闭，true-启用,示例值(true)
 *@param {string} id
 *@param {string} path  "http://"
 @param  useOrg
 @param useOrgId
 */
export function getYunxkSetSave(data) {
  return request({
    url: '/kingdee/yunxk/set/save',
    method: 'post',
    data,
  })
}

/**
 * 获取金蝶云星空公司配置
 */
export function getYunxkUserCfig() {
  return request({
    url: '/yunxk/user/getYunxkUserCfig',
    method: 'get',
  })
}

/**
 * 保存星空公司配置
 *@param id	配置ID
 *@param  userAddress	公司地址-详情地址
 *@param  userArea	公司地址-县/区
 *@param  userCity	公司地址-市
 *@param  userPhone 公司手机号前七位
 *@param  userProvince	公司地址-省
 */
export function saveUserCfig(data) {
  return request({
    url: '/yunxk/user/saveUserCfig',
    method: 'post',
    data,
  })
}

/**
 * 同步并保存星空公司配置
 *@param id	配置ID
 *@param  userAddress	公司地址-详情地址
 *@param  userArea	公司地址-县/区
 *@param  userCity	公司地址-市
 *@param  userPhone 公司手机号前七位
 *@param  userProvince	公司地址-省
 *@param progressUuid
 */
export function saveWithSyncUserCfig(data, progressUuid) {
  return request({
    url: `/yunxk/user/saveWithSyncUserCfig/${progressUuid}`,
    method: 'post',
    data,
  })
}

/**
 * 获取星空产品物料分类
 * @param limit
 * @param page
 * @param type	产品类型：1-成品，2-物料
 */
export function getGoodsTypeList(type: 1 | 2): AxiosPromise<XingKongAPIResponse.GoodMaterialTypes> {
  return request({
    url: `/yunxk/goods/getGoodsTypeList/${type}`,
    method: 'post',
  })
}

/**
 * 获取产品物料配置
 * @param type 产品类型：1-成品，2-物料
 */
export function getGoodsCfig(type) {
  return request({
    url: `/yunxk/goods/getGoodsCfig/${type}`,
    method: 'get',
  })
}

/**
 * 保存产品物料配置
 */
export function saveGoodsCfig(data) {
  return request({
    url: `/yunxk/goods/saveGoodsCfig`,
    method: 'post',
    data,
  })
}

/**
 *保存并同步物料
 * @param progressUuid	进度随机数
 */
export function saveSyncGoods(data: XingKongApiRequest.GoodMaterialAsync, progressUuid: number) {
  return request({
    url: `/yunxk/goods/saveSyncGoods/${progressUuid}`,
    method: 'post',
    data,
  })
}

/**
 *同步物料
 * @param progressUuid	进度随机数
 * @param type 同步的产品类型：1-成品，2-物料
 */
export function syncGoods(type, progressUuid) {
  return request({
    url: `/yunxk/goods/syncGoods/${type}/${progressUuid}`,
    method: 'post',
  })
}

/**
 *获取星空仓库配置
 */
export function getYunxkStoreCfig() {
  return request({
    url: `/yunxk/store/getYunxkStoreCfig`,
    method: 'get',
  })
}

/**
 * 保存星空仓库配置
 */
export function saveStoreCfig(data) {
  return request({
    url: `/yunxk/store/save`,
    method: 'post',
    data,
  })
}

/**
 *保存并同步仓库
 */
export function saveSyncStore(data, progressUuid) {
  return request({
    url: `/yunxk/store/saveSyncStore/${progressUuid}`,
    method: 'post',
    data,
  })
}

/**
 *同步仓库
 */
export function syncStore(progressUuid) {
  return request({
    url: `/yunxk/store/syncStore/${progressUuid}`,
    method: 'post',
  })
}

/**
 * 保存并同步其他出库单配置
 */
export function saveSyncOtherStore(progressUuid) {
  return request({
    url: `/yunxk/other/store/saveSyncOtherStore/${progressUuid}`,
    method: 'post',
  })
}

/**
 * 同步其他出库单配置
 */
export function syncOtherStore(progressUuid) {
  return request({
    url: `/yunxk/other/store/syncOtherStore/${progressUuid}`,
    method: 'post',
  })
}

/**
 * 保存并同步销售出库单配置
 *@param syncSaleOutStorePrice
 * 是否同步销售出库单物料价格：false-关闭，true-同步,示例值(true)
 */
export function saveSyncYunxkSaleStore(data, progressUuid) {
  return request({
    url: `/yunxk/sale/store/saveSyncYunxkSaleStore/${progressUuid}`,
    method: 'post',
    data,
  })
}

/**
 * 保存销售出库单配置
 * @param syncSaleOutStorePrice	是否同步销售出库单物料价格：false-关闭，true-同步,示例值(true)
 */
export function saveYunxkSaleStoreCfig(data) {
  return request({
    url: `/yunxk/sale/store/saveYunxkSaleStoreCfig`,
    method: 'post',
    data,
  })
}

/**
 * 同步销售出库单配置
 * @param syncSaleOutStorePrice	是否同步销售出库单物料价格：false-关闭，true-同步,示例值(true)
 */
export function syncYunxkSaleStore(progressUuid) {
  return request({
    url: `/yunxk/sale/store/syncYunxkSaleStore/${progressUuid}`,
    method: 'post',
  })
}

/**
 * 获取其他出库单的单据类型
 */
export function getOtherOutStoreBillType(data) {
  return request({
    url: `/kingdee/yunxk/reverse/writing/set/getOtherOutStoreBillType`,
    method: 'get',
    data,
  })
}

/**
 * 获取金蝶云星空公司数据
 * @param  
 * "name": "",公司名称
  "number": ""公司条码
 */
export function getUser(data) {
  return request({
    url: `/yunxk/user/getUser`,
    method: 'post',
    data,
  })
}

/**
 * 获取库存状态
 */
export function getStoreStockStatus() {
  return request({
    url: `/yunxk/store/getStoreStockStatus`,
    method: 'get',
  })
}

/**
 * 获取其他出库单反写配置
 */
export function getOtherOutStoreReverseWriting() {
  return request({
    url: `/kingdee/yunxk/reverse/writing/set/getOtherOutStoreReverseWriting`,
    method: 'get',
  })
}

/**
 * 获取库存组织
 */
export function getOrgList() {
  return request({
    url: `/yunxk/org/getOrgList`,
    method: 'get',
  })
}

/**
 * 保存星空接口状态
 * @param {boolean} enabled
 */
export function saveYunxkEnableCfig(data) {
  return request({
    url: `/kingdee/yunxk/set/saveYunxkEnableCfig?enabled=${data}`,
    method: 'post',
    data,
  })
}

/**
 *保存星空接口域名
 @param {string} path
 */
export function saveYunxkPathCfig(data) {
  return request({
    url: `/kingdee/yunxk/set/saveYunxkPathCfig?path=${data}`,
    method: 'post',
    data,
  })
}

/**
 *保存星空使用组织
 @param {string} useOrg
 @param {string} useOrgId
 */
export function saveYunxkOrgCfig(data) {
  return request({
    url: `/kingdee/yunxk/set/saveYunxkOrgCfig`,
    method: 'post',
    data,
  })
}

/**
 * 保存其他出库单反写配置
 */
export function saveOtherOutStoreCfig(data) {
  return request({
    url: `/kingdee/yunxk/reverse/writing/set/saveOtherOutStoreCfig`,
    method: 'post',
    data,
  })
}

/**
 * 同步星空公司
 */
export function syncUserCfig(progressUuid) {
  return request({
    url: `/yunxk/user/syncUserCfig/${progressUuid}`,
    method: 'post',
  })
}

/*******************************************用友配置对接***************************************************/
/**
 *获取用友设置配置
 */
export function getYongyouSetCfig() {
  return request({
    url: `/yongyou/set/getYongyouSetCfig`,
    method: 'get',
  })
}

/**
 *保存用友设置
 */
export function setYongyouSave(data) {
  return request({
    url: `/yongyou/set/save`,
    method: 'post',
    data,
  })
}

/**
 *获取用友产品分类
 * @param limit
 * @param page
 * @param type	产品类型：1-成品，2-物料
 */
export function getyongyouGoodsTypeList(goodsType) {
  return request({
    url: `/yongyou/goods/getGoodsTypeList/${goodsType}`,
    method: 'post',
  })
}

/**
 * 保存产品物料配置
 */
export function saveyongyouGoodsCfig(data) {
  return request({
    url: `/yongyou/goods/saveGoodsCfig`,
    method: 'post',
    data,
  })
}

/**
 * 同步产品物料
 */
export function saveyongyouSyncGoods(goodsType, progressUuid) {
  return request({
    url: `/yongyou/goods/saveSyncGoods/${goodsType}/${progressUuid}`,
    method: 'post',
  })
}

/**
 * 保存并同步产品物料
 */
export function saveWithSyncGoods(data, progressUuid) {
  return request({
    url: `/yongyou/goods/saveWithSyncGoods/${progressUuid}`,
    method: 'post',
    data,
  })
}

/**
 * 获取产品物料配置
 */
export function getyongyouGoodsCfig(goodsType) {
  return request({
    url: `/yongyou/goods/getGoodsCfig/${goodsType}`,
    method: 'get',
  })
}

/**
 *获取用友公司分类
 */
export function getYongyouCustomerType() {
  return request({
    url: `/yongyou/customer/type/getYongyouCustomerType`,
    method: 'post',
  })
}

/**
 * 获取公司配置
 */
export function getCustomerCfig() {
  return request({
    url: `/yongyou/customer/type/getCustomerCfig`,
    method: 'get',
  })
}

/**
 * 保存公司配置
 */
export function saveCustomerType(data) {
  return request({
    url: `/yongyou/customer/type/saveCustomerType`,
    method: 'post',
    data,
  })
}

/**
 *保存并同步公司
 */
export function saveSyncCustomerCfig(data, progressUuid) {
  return request({
    url: `/yongyou/customer/type/saveSyncCustomerCfig/${progressUuid}`,
    method: 'post',
    data,
  })
}

/**
 * 同步公司
 */
export function syncCustomer(progressUuid) {
  return request({
    url: `/yongyou/customer/type/syncCustomer/${progressUuid}`,
    method: 'post',
  })
}

/**
 * 获取用友仓库配置
 */
export function getYongyouStoreCfig() {
  return request({
    url: `/yongyou/store/getYongyouStoreCfig`,
    method: 'get',
  })
}

/**
 * 保存仓库配置
 */
export function saveYongyouStoreCfig(data) {
  return request({
    url: `/yongyou/store/saveYongyouStoreCfig`,
    method: 'post',
    data,
  })
}

/**保存并同步仓库 */
export function saveSyncStor(data, progressUuid) {
  return request({
    url: `/yongyou/store/saveSyncStor/${progressUuid}`,
    method: 'post',
    data,
  })
}

/**同步仓库 */
export function syncyongyouStore(progressUuid) {
  return request({
    url: `/yongyou/store/syncStore/${progressUuid}`,
    method: 'post',
  })
}

/**
 * 同步库存
 * @param progressUuid - uuid
 */
export function syncStoreStock(progressUuid) {
  return request({
    url: `/yongyou/store/syncStoreStock/${progressUuid}`,
    method: 'get',
  })
}

/**获取用友其他出库单配置 */
export function getOtherStoreCfig() {
  return request({
    url: `/yongyou/other/store/getOtherStoreCfig`,
    method: 'get',
  })
}

/**保存用友其他出库单配置
 * @param otherOutCustomerId 同步其他出库单默认补充收货公司ID
 * @param otherOutStoreTypeId 同步其他出库单默认补充单据类型ID
 */
export function saveOtherStoreCfig(data) {
  return request({
    url: `/yongyou/other/store/saveOtherStoreCfig`,
    method: 'post',
    data,
  })
}

/**保存并同步用友其他出库单
 * @param otherOutCustomerId 同步其他出库单默认补充收货公司ID
 * @param otherOutStoreTypeId 同步其他出库单默认补充单据类型ID
 */
export function saveyongyouSyncOtherStore(data, progressUuid) {
  return request({
    url: `/yongyou/other/store/saveSyncOtherStore/${progressUuid}`,
    method: 'post',
    data,
  })
}

/**同步用友其他出库单*/
export function syncyongyouOtherStore(progressUuid) {
  return request({
    url: `/yongyou/other/store/syncOtherStore/${progressUuid}`,
    method: 'post',
  })
}

// 获取用户下拉数据列表
export function selecUser(data) {
  return request({
    url: '/select/user/pageSelect',
    method: 'post',
    data,
  })
}

// 出库仓库类型下拉列表查询
export function outStoreTypePageSelect(data) {
  return request({
    url: '/store/select/outStoreTypePageSelect',
    method: 'post',
    data,
  })
}

/**获取用友网点分类 */
export function getYongyouNetworkType() {
  return request({
    url: '/yongyou/network/getYongyouNetworkType',
    method: 'get',
  })
}

/**保存网点分类配置 */
export function saveNetworkTypeCfig(data) {
  return request({
    url: '/yongyou/network/saveNetworkTypeCfig',
    method: 'post',
    data,
  })
}

/**保存并同步网点*/
export function saveSyncNetwork(data, progressUuid) {
  return request({
    url: `/yongyou/network/saveSyncNetwork/${progressUuid}`,
    method: 'post',
    data,
  })
}

/**保存并同步网点*/
export function syncNetwork(progressUuid) {
  return request({
    url: `/yongyou/network/syncNetwork/${progressUuid}`,
    method: 'post',
  })
}
/**同步条码*/
export function syncCode(uuid) {
  return request({
    url: `/yongyou/code/syncCode/${uuid}`,
    method: 'get',
  })
}

/**
 * 用友同步销售出库单
 * @param {number} uuid - 进度随机数
 * @returns {AxiosPromise}
 */
export function yongyouSyncSaleStore(
  uuid: number,
): AxiosPromise<{ code: number; data: object; message: string; success: boolean }> {
  return request({
    url: `/yongyou/sale/syncSaleStore/${uuid}`,
    method: 'get',
  })
}

/**
 * 获取用友销售出库设置
 */
export const getYongYouSaleWarehouseOutSet = (): AxiosPromise<
  APIResponse<{ saleStoreBillEndDate: string; saleStoreBillStartDate: string }>
> => {
  return request({
    url: '/yongyou/sale/getSaleStoreSet',
    method: 'get',
  })
}

/**
 * 保存用友销售出库设置
 * @param {Object} data - 请求参数
 * @param {String} data.saleStoreBillStartDate - 销售出库单同步开始时间
 * @param {String} data.saleStoreBillEndDate - 销售出库单同步结束时间
 */
export const saveYongYouSaleWarehouseOutSet = (data: {
  saleStoreBillEndDate: string
  saleStoreBillStartDate: string
}): AxiosPromise<APIResponse> => {
  return request({
    url: '/yongyou/sale/saveSaleStoreSet',
    method: 'post',
    data,
  })
}

/**
 * 保存并同步用友销售出库设置
 * @param {Object} data - 请求参数
 * @param {String} data.saleStoreBillStartDate - 销售出库单同步开始时间
 * @param {String} data.saleStoreBillEndDate - 销售出库单同步结束时间
 * @param {Number} uuid - 进度随机数
 */
export const saveYongYouSaleWarehouseOutSetAndSync = (
  data: { saleStoreBillEndDate: string; saleStoreBillStartDate: string },
  uuid: number,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/yongyou/sale/saveWidthSyncSaleStore/${uuid}`,
    method: 'post',
    data,
  })
}

/**
 * 同步条码
 * @param {Number} uuid - 进度uuid
 */
export const saveAsyncSnCode = (uuid: number) => {
  return request({
    url: `/yunxk/snCode/saveSyncSnCode/${uuid}`,
    method: 'get',
  })
}

/**
 * 同步仓库库存
 * @param {number} uuid - 进度id
 */
export const syncWarehouseStock = (uuid: number) => {
  return request({
    url: `/yunxk/store/syncStoreStock/${uuid}`,
    method: 'get',
  })
}


/**
 * 同步装配清单
 * @param {number} uuid - 进度id
 */
 export const syncMountings = (uuid: number) => {
  return request({
    url: `/mountings/bill/syncData/${uuid}`,
    method: 'post',
  })
}


/**
 * 同步dom
 * @param {number} uuid - 进度id
 */
 export const productSyncData = (uuid: number) => {
  return request({
    url: `/goods/product/bom/syncData/${uuid}`,
    method: 'post',
  })
}